const Logic = require('../logic');
module.exports = class extends Logic
{
    getAction()
    {
        return this.checkGetGuid();
    }

    /**
     * 上传作品
     * @returns {*}
     */
    uploadWorkAction()
    {
        let data = think.stringToJson(this.post('data'));
        if (data === false)
        {
            return this.fail(52004, '提交的表单信息错误,该数据必须为json格式,请检查数据格式,上传数据格式为{\'data\',yourJsonData},如 : $.post("http://127.0.0.1:8091/apiv1/competition",{\'data\':yourJsonData}),yourJsonData为你要上传的数据包');
        }
        let upworkRule = {
            stepguid: {type: "string", min: 36, max: 36},
            CoverUrl: {type: "string", min: 5},
            Title: {type: "string", min: 1},
            Desc: {type: "string", min: 1},
            Content: {type: "string", min: 10},
            userguid: {type: 'string', min: 1}
        };
        let vres = think.validate(data, upworkRule);
        if (vres === true)
        {
            this.ctx.state.uploadWorkData = data;
        } else
        {
            return this.error(52040, vres[0].message);
        }
    }
    async updateWorkAction()
    {
        let data = think.stringToJson(this.post('data'));
        if (data === false)
        {
            return this.fail(52004, '提交的表单信息错误,该数据必须为json格式,请检查数据格式,上传数据格式为{\'data\',yourJsonData},如 : $.post("http://127.0.0.1:8091/apiv1/competition",{\'data\':yourJsonData}),yourJsonData为你要上传的数据包');
        }
        let upworkRule = {
            wkguid: {type: "string", min: 36, max: 36},
            CoverUrl: {type: "string", min: 5},
            Title: {type: "string", min: 1},
            Desc: {type: "string", min: 1},
            Content: {type: "string", min: 10},
        };
        let vres = think.validate(data, upworkRule);
        if (vres === true)
        {
            this.ctx.state.updateWorkData = data;
        } else
        {
            return this.error(52040, vres[0].message);
        }

    }

};